package com.kotlin.usermodel.presenter

import com.kotlin.baselibrary.ext.execute
import com.kotlin.baselibrary.presenter.BasePresenter
import com.kotlin.baselibrary.rx.BaseSubscriber
import com.kotlin.usermodel.presenter.view.RegisterView
import com.kotlin.usermodel.service.UserService
import javax.inject.Inject
import javax.inject.Named

/**
 * @author       zhipe
 * @createTime    2020/10/12
 * @description
 */

class RegisterPresenter @Inject constructor() : BasePresenter<RegisterView>() {
    @Inject
    @Named("service1")
    lateinit var userService: UserService

    @Inject
    @Named("service2")
    lateinit var userService2: UserService


    fun register(phoneNumber: String, verifyCode: String, pwd: String) {
        userService.register(phoneNumber, verifyCode, pwd)
            .execute(object : BaseSubscriber<Boolean>() {
                override fun onNext(t: Boolean) {
                    mView.onRegisterResult(if (t)"注册成功" else "注册失败")
                }

                override fun onError(e: Throwable) {
                    super.onError(e)
                    mView.onRegisterResult("注册失败")
                }
            },lifeCycleProvider)

    }

    fun register2(phoneNumber: String, verifyCode: String, pwd: String) {
        userService2.register(phoneNumber, verifyCode, pwd)
            .execute(object : BaseSubscriber<Boolean>() {
                override fun onNext(t: Boolean) {
                    mView.onRegisterResult(if (t)"注册成功" else "注册失败")
                }

                override fun onError(e: Throwable) {
                    super.onError(e)
                    mView.onRegisterResult("注册成功")
                }
            },lifeCycleProvider)

    }
}